import java.util.Stack;

public class isValid {
    /**
     * 有效的括号
     * 方法是利用的栈，对应匹配之后出栈入栈
     */
    public static boolean method(String s){
        if(s.isEmpty()){
            return true;
        }
        Stack<Character> stack = new Stack<>();
        for(char c:s.toCharArray()){
            if(c == '('){
                stack.push(')');
            }else if(c == '{'){
                stack.push('}');
            }else if(c == '['){
                stack.push(']');
            }else if(stack.isEmpty() || c!= stack.pop()){
                return false;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        isValid is=new isValid();
        String s1="(){}[]";
        String s2="({})({}[]";

        System.out.println(method(s1));
        System.out.println(method(s2));
    }
}
